package com.qf.service.Impl;

import com.qf.mapper.ShpMapper;
import com.qf.mapper.UserMapper;
import com.qf.pojo.Shopping;
import com.qf.pojo.User;
import com.qf.service.ShpService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class ShpServiceImpl implements ShpService {

    @Autowired
    ShpMapper shpMapper;
    @Autowired
    UserMapper userMapper;

    @Override
    public Integer saveShopping(Integer goodsId, Integer count) {
        Subject subject = SecurityUtils.getSubject();
        String username = (String) subject.getPrincipal();


        User user=new User();
        user.setUsername(username);
        User param = userMapper.selectOne(user);


        Shopping shopping=new Shopping();
//        shopping.setId(null);

        shopping.setGoodsId(goodsId);

        shopping.setUserId(param.getId());
        shopping.setCount(count);
        shopping.setCreateTime(new Date());

        int shoppingCount = shpMapper.insertSelective(shopping);
        return shoppingCount;
    }
}
